<?php
require_once('connections/mysqlDB.php');
require('smarty_connect.php');
//include("check_reg_stop.php");

$smarty = new smarty_connect;
$dbConn = new mysqli(HOST,USER,PWD,DB);
if (mysqli_connect_errno()) { die('Connect failed: ' . mysqli_connect_error()); }  

if (isset($_SESSION['regid'])) {
$regid=  $_SESSION['regid'];
} else { $regid = 0;
}
$dbConn->query("SET NAMES 'utf8'");

// Check if conference registration already ends
$stmt1 = $dbConn->query("select datediff(registration_end_date, NOW()) as expire, title, conference_id from conference 
where location = 'San Francisco' order by conference_id desc limit 1; ");
while ($row=$stmt1->fetch_assoc()) {
  $expire = $row["expire"];
  $title = $row["title"];
  $conferenceid = $row["conference_id"];
};
$stmt1->close();

if ($expire < 0) {
$smarty->assign('error',"2009夏令會報名已截止  Conference Registration Ends on 6/27/2009");
$smarty->display('error.tpl');
} else 
{
session_register("expire");
session_register("title");
session_register("conferenceID");
$_SESSION['expire'] = $expire;
$_SESSION['conferenceID'] = $conferenceid;
$_SESSION['title']=$title;

$stmt1 = $dbConn->query("SELECT abbrev, trim(description) as description from code where code = 'country' order by id");
$country=array();
while ($row=$stmt1->fetch_array(MYSQL_NUM)) {
  $country[$row[0]]="$row[1]";
};
$stmt1->close();

// get state list
$stmt1 = $dbConn->query("SELECT abbrev, trim(description) as description from code where code = 'state' order by id");
$state=array();
while ($row=$stmt1->fetch_array(MYSQL_NUM)) {
  $state[$row[0]]="$row[1]";
};

$stmt1->close();

// get groups list
$stmt1 = $dbConn->query("SELECT abbrev, trim(description) as description from code where code = 'groups' order by id");
$groups=array();
while ($row=$stmt1->fetch_array(MYSQL_NUM)) {
  $groups[$row[0]]="$row[1]";
};
$stmt1->close();

// get special need  list
$stmt1 = $dbConn->query("SELECT abbrev, trim(description) as description from code where code = 'special need' order by abbrev");
$spneed=array();
while ($row=$stmt1->fetch_array(MYSQL_NUM)) {
  $spneed[$row[0]]="$row[1]";
};
$stmt1->close();

// get gender  list
$stmt1 = $dbConn->query("SELECT abbrev, trim(description) as description from code where code = 'gender' order by id");
$gender=array();
while ($row=$stmt1->fetch_array(MYSQL_NUM)) {
  $gender[$row[0]]="$row[1]";
};
$stmt1->close();

// get relationship  list
$stmt1 = $dbConn->query("SELECT abbrev, trim(description) as description from code where code = 'relationship' order by id");
$relationship=array();
while ($row=$stmt1->fetch_array(MYSQL_NUM)) {
  $relationship[$row[0]]="$row[1]";
};
$stmt1->close();

// get relationship  list
$stmt1 = $dbConn->query("SELECT cmid, church_name from church order by church_name");
$church=array();
while ($row=$stmt1->fetch_array(MYSQL_NUM)) {
  $church[$row[0]]="$row[1]";
};
  $church["0"]="其他 Other";
$stmt1->close();

// get conference title

/*  $result = mysqli_query($dbConn,"SELECT title FROM conference WHERE conference_id='2009Summer' ");
    // for each registration, print confirmation (rid)
    while ($row = mysqli_fetch_array($result)) {
        $title=$row["title"];
    }
//var_export($row);
$result->close();
*/

$dbConn->close();
$smarty->assign('title',$title);
$smarty->assign('regid',$regid);
$smarty->assign('state',$state);
$smarty->assign('country',$country);
$smarty->assign('groups',$groups);
$smarty->assign('spneed',$spneed);
$smarty->assign('gender',$gender);
$smarty->assign('relationship',$relationship);
$smarty->assign('church',$church);
$smarty->display('con_newreg2.tpl');

}
?>
